<?php
/*
Copyright FLV Hosting
*/

	require_once '../config.php' ;
    	//echo $_SERVER['PHP_AUTH_USER'];
	 //if(!isset($_SERVER['PHP_AUTH_USER']) || ($_SERVER['PHP_AUTH_USER']!=_ADMIN_LOGIN || $_SERVER['PHP_AUTH_PW'] != _ADMIN_PASSWORD)) {
	   //header('WWW-Authenticate: Basic realm="Administration"');
	   //header('HTTP/1.0 401 Unauthorized');
	   //echo '<p><center><b>This site requires a valid login and password.</b></center>';
	   //exit;
	 //}

		 $is_logged = Session::isLogin();
	 if  (!$is_logged) {
		header('Location: '. 'http://'._HOST.'/login.htm');
		return;
	 }

     $user_id = Session::getUserId();
     $is_admin = User::isUserAdmin($user_id);
     $is_author = User::isUserArticleWriter($user_id);
     if  (!$is_admin && !$is_author) {
		header('Location: '. 'http://'._HOST.'/myprofile/index.htm');
		return;
	 }


	require_once _LIB.'/abstract.php' ;
	require_once _LIB.'/mysql.php' ;
	require_once _LIB.'/paginate.php' ;
	require_once _LIB.'/main.php' ;

function check_table_exists() {
	global $CONN;
	$r = array();
	$result = mysql_list_tables(_DBNAME,$CONN->id);
	while ($row = mysql_fetch_row($result)) {
	   $r[] = $row[0];
	}
	mysql_free_result($result);
	//debug($r);
	if(in_array('player_movies',$r)) {
		return true;
	} // i f
	return false;
} // f u n c t i o n

function setup_tables() {

$q = <<<EOT
CREATE TABLE `player_movies` (
  `m_id` int(10) NOT NULL auto_increment,
  `m_name` varchar(255) NOT NULL default '',
  `m_thumb` varchar(255) NOT NULL default '',
  `m_var` varchar(255) NOT NULL default '',
  `m_file` varchar(255) NOT NULL default '',
  `m_fsize` int(10) NOT NULL default '0',
  `m_txt` text NOT NULL,
  `m_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `site_id` int(11) NOT NULL default '0',
  PRIMARY KEY  (`m_id`),
  UNIQUE KEY `m_file` (`m_file`)
) TYPE=MyISAM ;
EOT;
	global $CONN;
	$ret = $CONN->get_mod($q);
} // f u n c t i o n


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Manage movies</TITLE>
<link rel="stylesheet" type="text/css" href="admin.css">
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="10" topmargin="20" marginwidth="0" marginheight="0">

<TABLE border=0 cellspacing=0 cellpadding=10 align=center width=620>
<tr>
	<td width=160 style="border-right: 4px double red;" valign=top>
		<b>Help section:</b>
		<ul>
			<li style="font-size: xx-small;">Please check again values SITE_ROOT/config.php before you click install button.
		</ul>
	</td>
	<td valign=top>
		<h1>Player DB Installation.</h1>

<?php
	if(!empty($MSG)) {
		echo '<h2>'.$MSG.'</h2>'._E ;
	} // i f
?>

<?php
# right area
	if(!empty($CONN->id)) {
		echo '<p><b>Database connection successful.</b></p>';
		$ex = check_table_exists();
		if(isset($_REQUEST[go_setup]) && !$ex) {
			setup_tables();
			echo '<p><b>Tables have been set up, <a href="index.php">click here</a> to go to administration.</b></p>' ;
		} // i f
		elseif(!$ex) {
?>

<table align="center" width=100% border=1 cellspacing=2 cellpadding=2>
<form method=post>
<tr>
	<td align=center>
		<input type="submit" name="go_setup" value="setup the tables">
	</td>
</tr>
</form>
</table>

<?php
		} // e l s e i f
		else {
			echo 'Installation tables exist, please delete them first to reinstall.' ;
		} // e l s e
	} // i f
	else {
		echo '<p><b>Database connection unsuccessful, please check values in config.php.</b></p>';
	} // e l s e
# right area end
?>

	</td>
</tr>
<tr>
	<td colspan=2 align=center>
<BR>
<BR>
<BR>
<BR>
<a href="http://affiliates.macromedia.com/b.asp?id=2097&p=go/dr_home_aff1" target="_blank"><IMG SRC="../system/mwm_flmx_88_31.gif" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Powered By Flash MX"></A>&nbsp;&nbsp;<A HREF="http://www.php.net" target="_blank"><IMG SRC="../system/powered_by_php.jpg" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Powered By PHP"></A>&nbsp;&nbsp;<A HREF="http://www.macromedia.com/go/getflashplayer/" target="_blank"><IMG SRC="../system/alternate.gif" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Get the latest Free Flash Player"></A>
	</td>
</tr>
</table>

</BODY>
</HTML>
<?php
	echo $CONN->debug ;
?>